package methodExercises;

/**
 * @author: snail_mount
 * @date: 20/1/22 22:37
 * @description: 需求1：设计一个方法用于数组遍历，要求遍历的结果是在一行上的。例如：[11, 22, 33, 44, 55]
 */
public class MethodDemo01 {
    public static void main(String[] args) {
        int[] arr = {11, 22, 33, 44, 55};
        oneLine(arr);
    }

    private static void oneLine(int[] arr) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < arr.length; i++) {
            if (i == 0) {
                sb.append("[");
            }
            if (i == arr.length - 1) {
                sb.append(arr[i]).append("]");
            } else {
                sb.append(arr[i]).append(",");
            }
        }
        System.out.println(sb);
    }
}
